/*
 * MonomialProcedure.java
 *
 * Created on May 4, 2005, 7:27 PM
 *
 * To change this template, choose Tools | Options and locate the template under
 * the Source Creation and Management node. Right-click the template and choose
 * Open. You can then make changes to the template in the Source Editor.
 */

package com.milowski.monos.scheme;

import gnu.mapping.*;
import gnu.math.*;
import gnu.lists.*;
import com.milowski.monos.*;
import com.milowski.monos.binomial.*;

/**
 *
 * @author R. Alexander Milowski
 */
public class List2BinomialProcedure extends Procedure2
{
   
   /** Creates a new instance of MonomialProcedure */
   public List2BinomialProcedure()
   {
      super("list->binomial");
   }
   
   public List2BinomialProcedure(String name)
   {
      super(name);
   }
   
   public Object apply2(Object obj1, Object obj2) {
      LList list1 = (LList)obj1;
      LList list2 = (LList)obj2;
      int size1 = LList.length(list1);
      int size2 = LList.length(list2);
      if (size1!=size2) {
         throw new RuntimeException("The lists for list->binomial must be of the same length.");
      }
      FullBinomial b = new FullBinomial(size1);
      short [] values1 = b.getLeadingTerm();
      short [] values2 = b.getTrailingTerm();
      for (int i=0; i<size1; i++) {
         IntNum inum = (IntNum)list1.get(i);
         values1[i] = (short)inum.intValue();
         inum = (IntNum)list2.get(i);
         values2[i] = (short)inum.intValue();
      }
      return b;
   }
   
}
